package it.xiuxian.swindle.presenter

import com.lzy.okgo.OkGo
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.AESUtils
import it.xiuxian.swindle.bean.ImageBean
import it.xiuxian.swindle.fragment.GongYIFragment
import org.json.JSONObject
import java.io.File

class GongYIFragmentPresenter:BasePresenter<GongYIFragment>() {
    fun onload(file: File){
        OkGo.post<BaseBean<ImageBean>>(HttpConfig.BASE_URL + "/appgongyiqiang/uploadImg")
            .isMultipart(false)
            .params( "file", file)
            .execute(object : CallBackOption<BaseBean<ImageBean>>() {}.loadBind(mView as GongYIFragment).execute(
                object : ILoadBind<BaseBean<ImageBean>> {
                    override fun excute(bean: BaseBean<ImageBean>) {
                        if(bean.code==0){
                            (mView as GongYIFragment).updata(bean.data)
                        }
                    }
                }
            ))
    }
    fun submit(json1: JSONObject){
        var data= AESUtils.encryptAES_ECB(json1.toString())
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL+"/appgongyiqiang/tijiao")
            .params("encrypt", data)
            .execute(object : CallBackOption<BaseBean<String>>() {}.loadBind(mView as GongYIFragment).execute(
                object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        if(bean.code==0){
                            (mView as GongYIFragment).update(bean.msg)
                        }
                    }
                }
            ))
    }
}